﻿using System;
using System.Security.Cryptography;

namespace DimMock
{
    public partial class Random
    {
        private static int ArraySize()
        {
            int min = Generate.Next(0, Constants.ArrayMax - 1);
            int max = Generate.Next(min, Constants.ArrayMax);
            return Generate.Next(min, max);
        }

        public static System.String String()
        {
            return System.DateTime.Now.ToString();
        }

        public static System.String[] StringArray()
        {
            int size = ArraySize();
            System.String[] array = new string[size];

            int i = 0;
            do
            {
                array[i] = Random.String();
                i++;
            } while (i < array.Length);

            return array;
        }

        public static System.Boolean Boolean()
        {
            return Generate.Next(0, 1) > 0;
        }

        public static System.Boolean[] BooleanArray()
        {
            int size = ArraySize();
            System.Boolean[] array = new Boolean[size];

            int i = 0;
            do
            {
                array[i] = Random.Boolean();
                i++;
            } while (i < array.Length);

            return array;
        }

        public static System.UInt32 UInt()
        {
            return (uint)Generate.Next((int)uint.MinValue, int.MaxValue);
        }

        public static System.UInt32[] UIntArray()
        {
            int size = ArraySize();
            System.UInt32[] array = new UInt32[size];

            int i = 0;
            do
            {
                array[i] = Random.UInt();
                i++;
            } while (i < array.Length);

            return array;
        }

        public static System.UInt16 UInt16()
        {
            return (UInt16)Generate.Next((int)uint.MinValue, short.MaxValue);
        }

        public static System.UInt16[] UInt16Array()
        {
            int size = ArraySize();
            System.UInt16[] array = new UInt16[size];

            int i = 0;
            do
            {
                array[i] = Random.UInt16();
                i++;
            } while (i < array.Length);

            return array;
        }

        public static System.UInt64 UInt64()
        {
            return (UInt64)Generate.Next((int)uint.MinValue, int.MaxValue);
        }

        public static System.UInt64[] UInt64Array()
        {
            int size = ArraySize();
            System.UInt64[] array = new UInt64[size];

            int i = 0;
            do
            {
                array[i] = Random.UInt64();
                i++;
            } while (i < array.Length);

            return array;
        }

        public static System.Int32 Int()
        {
            return Generate.Next();
        }

        public static System.Int32 Int(int min, int max)
        {
            return Generate.Next(min, max);
        }

        public static System.Int32[] IntArray()
        {
            int size = ArraySize();
            System.Int32[] array = new Int32[size];

            int i = 0;
            do
            {
                array[i] = Random.Int();
                i++;
            } while (i < array.Length);

            return array;
        }

        public static System.Int64 Int64()
        {
            return Generate.Next();
        }

        public static System.Int64[] Int64Array()
        {
            int size = ArraySize();
            System.Int64[] array = new Int64[size];

            int i = 0;
            do
            {
                array[i] = Random.Int64();
                i++;
            } while (i < array.Length);

            return array;
        }

        public static System.Int16 Int16()
        {
            return (short)Generate.Next();
        }

        public static System.Int16[] Int16Array()
        {
            int size = ArraySize();
            System.Int16[] array = new Int16[size];

            int i = 0;
            do
            {
                array[i] = Random.Int16();
                i++;
            } while (i < array.Length);

            return array;
        }
        
        public static System.Guid Guid()
        {
            return System.Guid.NewGuid();
        }

        public static System.Guid[] GuidArray()
        {
            int size = ArraySize();
            System.Guid[] array = new Guid[size];

            int i = 0;
            do
            {
                array[i] = Random.Guid();
                i++;
            } while (i < array.Length);

            return array;
        }

        public static System.DateTime DateTime()
        {
            return System.DateTime.Now.Subtract(TimeSpan.FromDays(Random.Generate.Next(1, 1000)));
        }

        public static System.DateTime[] DateTimeArray()
        {
            int size = ArraySize();
            System.DateTime[] array = new DateTime[size];

            int i = 0;
            do
            {
                array[i] = Random.DateTime();
                i++;
            } while (i < array.Length);

            return array;
        }

        [Obsolete("This needs to be refactored to generate a more valid number.")]
        public static System.Decimal Decimal()
        {
            return new decimal(Random.Generate.Next());
        }

        public static System.Byte[] Byte()
        {
            using (var crypto = new RNGCryptoServiceProvider())
            {
                Byte[] bytes = new Byte[Random.Generate.Next(1, 20)];
                crypto.GetBytes(bytes);
                return bytes;
            }
        }
    }
}
